#!/usr/bin/env python
#_*_ coding:utf-8 _*_
from django import forms
from app01 import models
class UserForm(forms.Form):
    username = forms.CharField()
    user_group_id = forms.IntegerField(
        widget=forms.Select()
    )
    #下面的def注意缩进
    def __init__(self, *args, **kwargs):
        #super表示父类方法，super(ImportForm, self)表示执行当前类的父类方法
        super(UserForm, self).__init__(*args, **kwargs)
        #去数据库拿,下面的fields['user_group'],user_group只是一个名字而已
        self.fields['user_group_id'].widget.choices = models.UserGroup_New.objects.all().values_list('id','caption')
